#!/bin/bash
read -p "localhost login: " name
if [ "$name" = "tom" ]; then	
	read -s -p "Password:" passwd
		if [ "$passwd" = "tom" ]; then
			if test -s loginerr.log ; then
				echo -n "Last failed login:"
				tail -1 loginerr.log
				sed -i '$d' loginerr.log
			fi

			if test -s login.log; then
				echo -n "Last login:"
				tail -1 login.log
			fi
			echo -n `date` >> login.log
			echo -n " on " >> login.log
			echo `tty` >> login.log
			echo "\n"
			echo -n "Welcome "
			echo `uname -r`
		else
			echo "\n"
			echo "Login incorrect"
			echo -n `date` >> loginerr.log
			echo -n " on " >> loginerr.log
			echo `tty` >> loginerr.log
		fi
else
	echo "\n"
	echo "Login incorrect"
	echo -n `date` >> loginerr.log
	echo -n " on " >> loginerr.log
	echo `tty` >> loginerr.log
fi				
